<!DOCTYPE html>
<html>
<head>
	<title>{$pageData.title}</title>
	<script type="text/javascript" src="__STATIC__/common/js/jquery.min.js"></script>
</head>
<body>
<p>标题：<div id="subject-title"></div></p>
<p>内容：<div id="subject-content"></div></p>
<div id="replys"></div>

继续提问：
<div id="ask">
<form>
<textarea name="content" cols="50" rows="10"></textarea>
<input type="hidden" name="post_time" value="{:time()}">
<input type="hidden" name="pid" value="{$id}">
<input type="button" value="提交" onclick="submitAsk()">
</form>
</div>
<script type="text/javascript">
$(function(){
	getData();
})

function getData(){
	$.ajax({
		'type':'post',
		'dataType':'json',
		'data':'id={$id}',
		'url':'{:url('consult.api/row')}',
		'success':function(data){
			$("#subject-title").html(data.title);
			$("#subject-content").html(data.content);
			var replyHtml = '';
			$.each(data.replys,function(index,value){
				if(value.uid==0){
					poster = '管理员'+value.admin_id+'：';
				}else{
					poster = '我：';
				}
				replyHtml += '<div class="reply">['+value.create_date+']'+poster+value.content+'</div>';
			});
			$("#replys").html(replyHtml);
		}
	});
}

function submitAsk(){
	var title='回复：'+$("#subject-title").text();
	var content = $("textarea[name=content]").val();
	var post_time = $("input[name=post_time]").val();
	var pid = $("input[name=pid]").val();
	$.ajax({
		'type':'post',
		'dataType':'json',
		'url':"{:url('consult.handle/submit')}",
		'data':'title='+title+'&content='+content+'&post_time='+post_time+'&pid='+pid+'&token={$token}',
		'success':function(data){
			alert(data.msg);
			if(data.code==1){
				$("#replys").append('<div class="reply">[刚刚]我：'+content+'</div>');
			}
		}
	});
}
</script>
</body>
</html>